const axios = require('axios');
const MockAdapter = require('axios-mock-adapter');
const normalAxios = axios.create();
const mockAxios = axios.create();
import url_config from "./config";
import reqTools from "../utils/reqTools";

// mock 数据  资源  声波锁离线版
var mock = new MockAdapter(mockAxios);

mock.onPost('/addHard').reply((config) => {
  return new Promise(function(resolve, reject) { 
    reqTools.post('/api/hardInfo', config.data).then((res) => {
     resolve([200, res ]);
   }).catch((err) => {
     resolve([500, err ]);
   });
 });
});

mock.onGet('/queryAll').reply((config) => {
  config.type="5"
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/hardInfo/agent',
    config).then((res) => {
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });

});

mock.onDelete('/deleteHard').reply((config) => {
  /* return new Promise(function(resolve, reject) {
    reqTools.delete( '/api/sysCnotice/'+config.id).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  }); */

  return new Promise(function(resolve, reject) {
    const ids= config.ids;
    reqTools.delete('/api/hardInfo/deletes',{ids}).then((res) => {
      resolve([200, res]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onPut('/updateHard').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.put( '/api/hardInfo',config.data,
     ).then((res) => {
      resolve([200, res ]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

mock.onGet('/sysUser/getRegisterTargetCount').reply((config) => {
  return new Promise(function(resolve, reject) {
    reqTools.get('/api/communityAcoust/getRegisterTargetCount',
    config).then(res => {
      console.log(res)
      resolve([200, res.data]);
    }).catch((err) => {
      resolve([500, err ]);
    });
  });
});

export default mockAxios;
